package com.tos.controller;


import com.tos.pojo.Manager;

import com.tos.pojo.Passenger;
import com.tos.service.ManagerService;
import com.tos.service.PassengerService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;




@RestController
@RequestMapping("/admin")
public class ManagerController {

    @Autowired
    private ManagerService managerService;

    @Autowired
    private PassengerService passengerService;



    @RequestMapping("/login")
    public String managerLogin(@RequestBody Manager manager) {



        Manager managerbean = managerService.getManager(manager.getUserName());
        if (managerbean == null) {
            return "用户不存在";
        }
        if (manager.getPassword() != null && manager.getPassword().equals(managerbean.getPassword())) {
            return "success";
        } else {
            return "密码错误，请重新输入";
        }
    }



    @RequestMapping("/deletePassenger")
    public String deletePassenger(@RequestBody Passenger passenger) {
        System.out.println("执行了deletePassenger");
        System.out.println("passenger.getPhone() = " + passenger.getPhone());
        boolean result = passengerService.deletePassenger(passenger.getPhone());
        if(result){
            return "success";
        }
        return "fail";
    }

}
